.\" Copyright (c) 2014 Andriy Gapon <avg@FreeBSD.org>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd July 17, 2019
.Dt GPTZFSBOOT 7
.Os
.Sh NAME
.Nm gptzfsboot
.Nd disk bootcode for BIOS-based computers
.Sh DESCRIPTION
.Nm
is used on BIOS-based computers to boot from a filesystem on disk device.
Depending on disk partitioning and boot file system, the
.Nm
is installed in a
.Cm zfs pool boot area
or
.Cm boot
partition of a disk with
.Xr installboot 8 .
.Ss IMPLEMENTATION NOTES
The GPT standard allows a variable number of partitions, but
.Nm
only boots from tables with 128 partitions or less.
.Ss BOOTING
.Nm
tries to find all ZFS pools that are composed of BIOS-visible
hard disks or partitions on them.
.Nm
looks for ZFS device labels on all visible disks and in discovered
supported partitions for all supported partition scheme types.
Disks are probed in BIOS defined order.
After a disk is probed and
.Nm
determines that the whole disk is not a ZFS pool member, the
individual partitions are probed in their partition table order.
Currently GPT and MBR partition schemes are supported.
.Pp
The default boot partition is recorded into
.Nm
binary by
.Xr installboot 8
and the default boot file system is determined at run time.
.Nm
does support booting from the
.Cm ZFS ,
.Cm UFS
and
.Cm PCFS
file systems.
.Pp
The filesystem specified by the
.Cm bootfs
property of the ZFS pool is used as a default boot filesystem.
If the
.Cm bootfs
property is not set, then the root filesystem of the pool is used as
the default.
.Xr loader 7
is loaded from the boot filesystem.
If
.Pa /boot/config
is present in the boot filesystem, boot options are read from it.
.Pp
The ZFS GUIDs of the boot pool and boot file system are made available to
.Xr loader 7 .
.Ss USAGE
Normally
.Nm
will boot in fully automatic mode.
However, it is possible to interrupt the automatic boot process and
interact with
.Nm
through a prompt.
.Pp
The filesystem specification and the path to
.Xr loader 7
is specified as
.Pp
.Sm off
.Oo zfs:pool/filesystem: Oc Oo /path/to/loader Oc
.Sm on
.Pp
Both the filesystem and the path can be specified.
If only a path is specified, then the default filesystem is used.
If only a pool and filesystem are specified, then
.Pa /boot/loader
is used as a path.
.Pp
Additionally, the
.Nm
does support two commands to get information about the system.
.Ic ?directoryname
can be used to list the content of named directory and
.Ic status
command can be used to query information about discovered devices.
The output format for ZFS pools is similar to that of
.Cm zpool status
.Pq see Xr zpool 8 .
.Pp
The configured or automatically determined ZFS boot filesystem is
stored in the
.Xr loader 7
.Cm loaddev
variable, and also set as the initial value of the
.Cm currdev
variable.
.Sh OPTIONS
The following options are supported by
.Nm
and
.Xr loader 7 :
.Bl -tag -width indent
.It Fl D
Dual console.
Use both text and serial console with
.Nm
and
.Xr loader 7 .
.It Fl P
Probe for keyboard.
If there is no keyboard, switch on the dual console and serial console.
.It Fl S Ns Ar speed
Set serial port speed.
.It Fl h
Set serial console.
.It Fl q
Keep the
.Nm
console quiet.
.It Fl t
Keep the VGA text mode for
.Xr loader 7 .
.El
.Pp
The following options will be passed to the kernel:
.Bl -tag -width indent
.It Fl s
Single user
.It Fl v
Verbose boot
.El
.Sh FILES
.Bl -tag -width /boot/gptzfsboot -compact
.It Pa /boot/config
parameters for the boot block
.Pq optional
.It Pa /boot/gptzfsboot
boot code binary
.El
.Sh EXAMPLES
.Nm
is installed in combination with a
.Dq protective MBR
.Po
see
.Xr installboot 8
.Pc .
To install
.Nm
on the
.Pa c0t0d0s0
drive:
.Bd -literal -offset indent
installboot /boot/pmbr /boot/gptzfsboot /dev/rdsk/c0t0d0s0
.Ed
.Sh SEE ALSO
.Xr loader 7 ,
.Xr installboot 8 ,
.Xr zpool 8
